//
//  XLAlertCommitView.m
//  XiangLove
//
//  Created by 宋振 on 2018/8/30.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLAlertCommitView.h"

@implementation XLAlertCommitView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.backgroundColor = RGBA(0, 0, 0, 0.4);
        
        //点击删除
        [self addTapGesture];
        
        //绘制界面信息
        [self setAlertView];
    }
    
    return self;
}

/**
 点击删除信息
 */
- (void)addTapGesture
{
    UITapGestureRecognizer *tapView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGetureAction:)];
    tapView.numberOfTapsRequired = 1;
    tapView.numberOfTapsRequired = 1;
    
    [self addGestureRecognizer:tapView];
}

/**
 设置弹窗提示
 */
- (void)setAlertView
{
    UIView *backgroundV = [[UIView alloc] init];
    backgroundV.backgroundColor = RGB(255, 255, 255);
    backgroundV.layer.cornerRadius = 12;
    backgroundV.layer.masksToBounds = YES;
    [self addSubview:backgroundV];
    
    [backgroundV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(270, 182));
    }];
    
    //标题
    UILabel *titleLbl = [[UILabel alloc] init];
    titleLbl.textAlignment = NSTextAlignmentCenter;
    titleLbl.attributedText = [[NSAttributedString alloc] initWithString:@"温馨提示" attributes:@{
                                                                                              NSKernAttributeName:@1,
                                                                                              NSForegroundColorAttributeName:RGB(3, 3, 3),
                                                                                              NSFontAttributeName:[UIFont systemFontOfSize:17]
                                                                                              }];
    [backgroundV addSubview:titleLbl];
    
    [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backgroundV.mas_top).offset(11);
        make.centerX.equalTo(backgroundV.mas_centerX);
        make.height.mas_equalTo(24);
    }];
    
    //提示信息
    UILabel *descripLbl = [[UILabel alloc] init];
    
    descripLbl.textAlignment = NSTextAlignmentCenter;
    descripLbl.numberOfLines = 2;
    descripLbl.attributedText = [[NSAttributedString alloc] initWithString:@"需要您至少上传2张个人照片 才能发现更多的小哥哥" attributes:@{
                                                                                                                    NSKernAttributeName:@1,
                                                                                                                    NSForegroundColorAttributeName:RGB(84, 84, 90),
                                                                                                                    NSFontAttributeName:[UIFont systemFontOfSize:15]
                                                                                                                    }];
    [backgroundV addSubview:descripLbl];
    
    [descripLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLbl.mas_bottom).offset(19);
        make.left.equalTo(backgroundV.mas_left).offset(18);
        make.right.equalTo(backgroundV.mas_right).offset(-18);
    }];
    
    //确定按钮
    UIButton *clickButton = [[UIButton alloc] init];
    
    clickButton.layer.cornerRadius = 5;
    clickButton.layer.masksToBounds = YES;
    [clickButton setTitle:@"确定" forState:(UIControlStateNormal)];
    [clickButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    clickButton.backgroundColor = RGB(255, 187, 1);
    [clickButton addTarget:self action:@selector(clickOkButton:) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:clickButton];
    
    [clickButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundV.mas_left).offset(15);
        make.right.equalTo(backgroundV.mas_right).offset(-15);
        make.bottom.equalTo(backgroundV.mas_bottom).offset(-16);
    }];
    
}

//点击
- (void)clickOkButton:(UIButton *)sender
{
    if (self.clickButton) {
        self.clickButton();
    }
}

- (void)tapGetureAction:(UITapGestureRecognizer *)tap
{
    if (self.clickButton) {
        self.clickButton();
    }
}

@end
